function addListenerPush() {
  //#ifdef APP-PLUS
  plus.runtime.setBadgeNumber(0)
  plus.push.addEventListener('click', msg => {
    let data = typeof msg.payload === 'string' && msg.payload !== '' ? JSON.parse(msg.payload) : msg.payload
    pushClick(data)
  }, false)

  plus.push.addEventListener('receive', msg => {
    let payload = msg.payload
    // IOS接收后创建本地消息,本地消息会再次触发receive,所以判断是否本地创建的,将其它数据封装在payload(需为字符串)中
    // 直发时，content = payload = {}
    if (plus.os.name !== 'Android' && msg.type === 'receive') {
      let content = payload.content
      let tit = payload.title
      let pl = {
        'title': tit,
        'content': content,
        ...payload
      }
      plus.push.createMessage(content, JSON.stringify(pl), {'title': tit})
    }

    if (plus.os.name === 'Android' && msg.content.indexOf('{') === 0) {
      let content = payload.content
      let tit = payload.title
      let pl = {
        'title': tit,
        'content': content,
        ...payload
      }
      plus.push.createMessage(content, JSON.stringify(pl), {'title': tit})
    }

    if (plus.os.name === 'Android' && msg.content.indexOf('{') === -1) {
      let pl = {
        'title': msg.title,
        'content': msg.content,
        ...payload
      }
      console.log(pl)
      plus.push.createMessage(msg.content, JSON.stringify(pl), {'title': msg.title})
    }
  }, false)
  //#endif
}

// 点击消息
function pushClick(data) {
  let msg = data.data
  console.log(msg)
  if(msg.type === 'link') {
    uni.navigateTo({
      url: msg.href
    })
  }
}

export default addListenerPush